import 'package:flutter/material.dart';
import 'package:flutter_book_store/login/login.dart';
import 'package:flutter_datetime_picker/flutter_datetime_picker.dart';
import 'package:get/get.dart';

import 'user_model.dart';

class UserInfoPage extends GetView<UserModel>{
  Map<String, dynamic> data = Map();
  var nickname = 'NICK_NAME_KEY';
  var radios = <String>['男', '女'];

  // var myDate = "hahahahaha dashabi";

  @override
  Widget build(BuildContext context) {

    return Scaffold(
      backgroundColor: Colors.white,
      appBar: AppBar(title: Text('个人信息设置')),
      body: SingleChildScrollView(
        child: Padding(
          padding: const EdgeInsets.symmetric(horizontal: 16),
          child: Column(
            children: [
              UserInfoText(
                space: 20,
                title: '用户名',
                content: '哈哈哈哈',
              ),
              UserInfoText(
                space: 36,
                title: '邮箱',
                content: '哈哈哈哈',
              ),
              InputText(
                data: data,
                dataKey: nickname,
                title: '昵称',
                space: 36,
                hintText: '请输入昵称',
                obscureText: false,
              ),
              Row(
                children: [
                  Text(
                    '性别',
                    style: TextStyle(fontSize: 16, color: Colors.grey.shade600),
                  ),
                  SizedBox(
                    width: 36,
                  ),
                  Row(
                    children: radios
                        .map((e) => Row(
                              children: [
                                Text('男'),
                                Radio<String>(
                                  activeColor: Colors.blue,
                                  value: e,
                                  groupValue: '男',
                                  onChanged: (v) {},
                                )
                              ],
                            ))
                        .toList(),
                  ),
                ],
              ),
              Padding(
                padding: const EdgeInsets.symmetric(vertical: 16),
                child: Row(
                  children: [
                    Text(
                      '生日',
                      style: TextStyle(fontSize: 16, color: Colors.black),
                    ),
                    SizedBox(
                      width: 36,
                    ),
                    GestureDetector(
                      onTap: () {
                        DatePicker.showDatePicker(context,
                            showTitleActions: true,
                            minTime: DateTime(1900, 1, 1),
                            maxTime: DateTime.now(),
                            theme: DatePickerTheme(
                                headerColor: Colors.white,
                                backgroundColor: Colors.white,
                                itemStyle: TextStyle(
                                    color: Colors.black,
                                    // fontWeight: FontWeight.bold,
                                    fontSize: 18),
                                doneStyle: TextStyle(
                                    color: Colors.blue, fontSize: 16)),
                            onChanged: (date) {}, onConfirm: (date) {
                          controller.myDate.value = '$date';
                          print('confirm $date');
                          // });
                        }, currentTime: DateTime.now(), locale: LocaleType.zh);
                      },
                      child: Obx(() => Text(controller.myDate.value,
                          style: TextStyle(fontSize: 16, color: Colors.black))),
                    ),
                  ],
                ),
              ),
              Container(
                height: 1,
                color: Colors.grey.shade300,
                width: double.infinity,
              ),
              InputText(
                space: 36,
                data: data,
                dataKey: nickname,
                title: '手机',
                hintText: '请输入您的手机号',
                obscureText: false,
              ),
              SizedBox(
                height: 36,
              ),
              RoundButton(
                title: '提交',
                color: Colors.blue,
                onPressed: () {},
              ),
            ],
          ),
        ),
      ),
    );
  }
}

class UserInfoText extends StatelessWidget {
  final title;
  final content;
  final double space;

  const UserInfoText({Key key, this.title, this.content, this.space})
      : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Column(
      children: [
        Padding(
          padding: const EdgeInsets.symmetric(vertical: 16),
          child: Row(
            children: [
              Text(
                title,
                style: TextStyle(fontSize: 16, color: Colors.grey.shade600),
              ),
              SizedBox(
                width: space == null ? 0 : space,
              ),
              Text(
                content,
                style: TextStyle(fontSize: 16, color: Colors.grey.shade600),
              ),
            ],
          ),
        ),
        Container(
          height: 1,
          color: Colors.grey.shade300,
          width: double.infinity,
        )
      ],
    );
  }
}
